<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="../../plugins/mui/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/chineseHospital/registration.css" />
		<script src="../../js/statistics.js"></script>
		<style>
			.header a{
				color:#fff;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav header">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">挂号信息</h1>
		</header>
		<div class="body">
			<div class="success" style="display: none;">
				<img src="../../images/icon/chineseHospital/success.png">
				<span>预约成功</span>
				<p>支付金额：<em></em>元</p>
			</div>
			<div class="title">
				<p>
					<span>就诊人信息</span>
				</p>
				
			</div>
			<div class="list">
				<p>
					<span>就诊信息</span>
				</p>
				<div class="info-list">
					
				</div>
				<div class="code" style="display: none;">
					<p>
						<span>就诊预约号：</span>
						<span></span>
					</p>
					<!--<img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1507720732728&di=9314be90b6e2319f779e4db85be96d6d&imgtype=0&src=http%3A%2F%2Fa.hiphotos.baidu.com%2Fexp%2Fwhcrop%3D160%2C120%2Fsign%3D2c94c593840a19d8cb56d2475c8abfba%2F91ef76c6a7efce1b7d3d54e8ab51f3deb48f65fa.jpg" />-->
				</div>
			</div>
			<div class="appointment check">
				确认预约
			</div>
		</div>
		<script src='../../plugins/jquery/jquery-3.1.0.min.js'></script>
		<script src="../../plugins/mui/mui.min.js"></script>
		<script src="../../js/getApiToken.js"></script>
		<script src='../../plugins/template/template.js'></script>
		<script type="text/javascript" src="../../js/md5.js" ></script>
		<script src='../../plugins/fontset/fontset.js'></script>
		<script src="../../js/alipay.js" ></script>
		<script type="text/html" id="title">
			{{if data.certification == 0}}
			<div class="no-authentication">
				<p>
					你还没有进行实名认证,请先完成认证后再进行预约
				</p>
				<span>实名认证</span>
			</div>
			{{else if data.certification == 2}}
			<div class="no-authentication">
				<p>
					正在实名认证中，请耐心等候......
				</p>
			</div>
			{{else}}
			<div class="authentication info-list">
				<ul>
					<li>
						<span>就诊人：</span>
						<span id="patient">{{data.name}}</span>
					</li>
					<li>
						<span>医疗卡号：</span>
						<span id="card">{{data.id}}</span>
					</li>
					<li>
						<span>就诊费用：</span>
						<span id="cost">{{data.price}}</span>
					</li>
				</ul>
			</div>
			{{/if}}
		</script>
		<script type="text/html" id="list">
			<ul>
				<li>
					<span>就诊科室：</span>
					<span id="first">{{data.first}}</span>
				</li>
				<li>
					<span>诊室名称：</span>
					<span id="second">{{data.office}}</span>
				</li>
				<li>
					<span>医师姓名：</span>
					<span id="doctor">{{data.doctor}}</span>
				</li>
				<li>
					<span>就诊类型：</span>
					<span id="type">{{data.type}}</span>
				</li>
				<li>
					<span>就诊日期：</span>
					<span id="date">{{data.date}}</span>
				</li>
				<li>
					<span>就诊时段：</span>
					<span id="time">{{data.time}}</span>
				</li>
				<li>
					<span>就诊地点：</span>
					<span id="address">{{data.adress}}</span>
				</li>
			</ul>
		</script>
		<script type="text/javascript">
			mui.init();
			
			mui.plusReady(function(){
				var pbbh = plus.webview.currentWebview().pbbh,
					ysbm = plus.webview.currentWebview().ysbm,
					card,certification;
				
				myAjax('home/Hospital_service/registration','get',{
					'iysbm':ysbm,
					'cpbbh':pbbh,
					'uid':plus.storage.getItem('cg_user_id')
				},function(data){
					console.log(JSON.stringify(data))
					if(data.code == 1){
						if(data.data.type.indexOf('(' && ')') >= 0){
							var reg =/\(.*\)/;
							data.data.type  = data.data.type.replace(reg,'');
						}
						if(data.data.adress == '' || !data.data.adress){
							data.data.adress = '暂无';
						}
						if(data.data.id == '' || !data.data.id){
							data.data.id = '暂无';
						}
						card = data.data.card;
						certification = data.data.certification;
						initData(data.data);
						
					}
				})
				$(".check").off().on('tap',function(){
					if(certification != 1){
						mui.toast('请先完成实名认证');
						return false;
					}
					var wait = plus.nativeUI.showWaiting('提交中...');
					var data = {
						'patient':$("#patient").text(),
						'id':$("#card").text(),
						'cost':$("#cost").text(),
						'firstOffice':$("#first").text(),
						'secondOffice':$("#second").text(),
						'doctor':$("#doctor").text(),
						'type':$("#type").text(),
						'date':$("#date").text(),
						'time':$("#time").text(),
						'address':$("#address").text()
					}
					console.log(JSON.stringify(data))
					myAjax('home/Hospital_service/order','post',{
						'patient':data.patient,
						'id':data.id,
						'cost':data.cost,
						'firstOffice':data.firstOffice,
						'secondOffice':data.secondOffice,
						'doctor':data.doctor,
						'type':data.type,
						'date':data.date,
						'time':data.time,
						'adress':data.address,
						'uid':plus.storage.getItem('cg_user_id'),
						'cpbbh':pbbh,
						'iysbm':ysbm,
						'card':card
					},function(data){
						plus.nativeUI.closeWaiting();
						if(data.code == 1){
							var res =data.data;
							//back();	
							myAjax('/home/hospitalService/alipay','POST',res,function(e){				
								if(e.success === true){
									var server = e.data;									
									getChannels(server,res,back,'true');
								}
							});
						}else{
							var message = data.msg.split('@');
							mui.toast('预约失败，' + message[message.length - 1]);
						}
					})
				});
				$(".body").delegate('.back-index','tap',function(){
					if(!$(this).hasClass('check')){
						mui.back();
					}
				})
				$(".body").delegate('.no-authentication span','tap',function(){
					mui.openWindow({
						url:'../my/user-4.html'
					})
				});
				window.addEventListener('refresh',function(){
					plus.webview.currentWebview().reload();
				})
			});
			$(function(){
				
			});
			function initData(data){
				var body = {
					data:data
				};
				var html = template('title',body),
					html2 = template('list',body)
				$(".title").append(html);
				$(".list .info-list").html(html2);
			}
			function back(extras){
				if(!extras){
					$(".success").slideDown().find('em').hide();
					if(res){
						$(".code>p").find('span:last-child').text(res.cyyh);
					}					
				}else{
					$(".success").slideDown().find('em').html(extras.money);
					$(".code>p").find('span:last-child').text(extras.cyyh);
				}
				mui.scrollTo(0,100);
				var html = '<div class="appointment back-index">返回医院主页</div>';
				$(".check,.back-index").remove();
				$(".body").append(html);
				$(".code").show();
				mui.back = function(){
                    var index = plus.webview.getWebviewById('registration_chineseHospital.html');
					if(index){
						plus.webview.show(index,'fade-in',200,function(){
							index.reload();
							
						})
					}else{
						var  w = plus.webview.create('../executive_housekeeper/registration_chineseHospital.html','registration_chineseHospital.html');
						w.show();
						plus.webview.getWebviewById('chineseHospital/index.html').close();
					}
					plus.webview.getWebviewById('section.html').close();
					plus.webview.getWebviewById('doctor.html').close();
					plus.webview.currentWebview().close();
				}
			}
		window.addEventListener("isPay",function(e){
			var cyyh = e.detail.cyyh,
				money = e.detail.money,
				data ={
					cyyh:cyyh,
					money:money
				};
			myAjax('/home/hospitalService/orderIsPay','POST',{cyyh:cyyh},function(e){
				if(e.code == 1){
					back(data);
				}else{
					mui.toast('支付失败，请重试');
				}
			})	
		})
		</script>
	</body>
</html>